Skip to content

Conversation

@CacheControl
Copy link
Owner

Uses the emitAsync() feature of EventEmitter2 to ensure promises returned to emitted events resolve before engine continues

Copy link

@naveen-shetty naveen-shetty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @CacheControl for making this change. Just a couple of things I noticed.

src/engine.js Outdated
almanac.factValue('success-events', { event: ruleResult.event })
return Promise.all([
this.emitAsync('success', ruleResult.event, almanac, ruleResult),
this.emitAsync(ruleResult.event.type, ruleResult.event.params, almanac, ruleResult)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current implementation success & ruleResult.event.type is triggered sequentially. This change is triggering them concurrently. Not a problem for us but just wanted to check if it is intentional.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another good call out! I can't see a good reason reason to deviate from the previous behavior; I've updated this to fire these in series, like it did before.

src/engine.js Outdated
this.emit('success', rule.event, almanac, ruleResult)
this.emit(rule.event.type, rule.event.params, almanac, ruleResult)
almanac.factValue('success-events', { event: rule.event })
almanac.factValue('success-events', { event: ruleResult.event })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As almanac.factValue returns a promise, Shouldn't this go inside Promise.all array as well?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yikes, that promise handling has been broken for a while. good catch!

@CacheControl CacheControl changed the base branch from master to next-major December 12, 2020 22:27
@CacheControl
Copy link
Owner Author

Thanks for the code review @naveen-shetty ! I've tweaked a few things and added docs/examples, but from a consumer's perspective the functionality hasn't changed since the 6.0.0-alpha-3 tag - feel free to use that until I release 6.0.0. I'm merging this into the next-major branch for the time being.

@CacheControl CacheControl merged commit cc5e3fd into next-major Dec 12, 2020
@CacheControl CacheControl deleted the promisify-events branch December 12, 2020 22:55
@naveen-shetty

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants